package com.gistmap.sideline.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gistmap.sideline.common.PageParam;
import com.gistmap.sideline.dto.SidelineDTO;
import com.gistmap.sideline.entity.Sideline;
import com.gistmap.sideline.mapper.SidelineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SidelineService {

    @Autowired
    private SidelineMapper sidelineMapper;

    public List<Sideline> findAll(PageParam pageParam){
        IPage<Sideline> userPage = new Page<>(pageParam.page, pageParam.size);
        // 第二个参数为封装wrapper
        userPage = sidelineMapper.selectPage(userPage, null);
        return userPage.getRecords();
    }

    public void save(SidelineDTO dto) {
        Sideline sideline = new Sideline();
        sideline.setContent(dto.getContent());
        sideline.setCategoryId(dto.getCategoryId());
        sidelineMapper.insert(sideline);
    }
}
